#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "mygrafx.h"
#include <string>

using namespace std;

mygrafx::mygrafx()
{
    //Screen attributes
    SCREEN_WIDTH = 800;
    SCREEN_HEIGHT = 550;
    SCREEN_BPP = 32;

    //Set up the screen
    screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );

    SDL_WM_SetCaption( "Game", NULL );
}

//mygrafx::mygrafx(char* image_file)
mygrafx::mygrafx(char* image_file)
{
	unopt_picture = IMG_Load(image_file);

	if (unopt_picture == NULL) {
		fprintf(stderr, "Couldn't load %s: %s\n", "Image", SDL_GetError());
		//return 0;
	}


	picture = SDL_DisplayFormat(unopt_picture);

	SDL_FreeSurface( unopt_picture );


    if( unopt_picture != NULL )
    {
        //Map the color key
        Uint32 colorkey = SDL_MapRGB( picture->format, 0, 0xFF, 0xFF );
        //Set all pixels of color R 0, G 0xFF, B 0xFF to be transparent
        SDL_SetColorKey( picture, SDL_SRCCOLORKEY, colorkey );
    }

}


void mygrafx::apply_surface( int x, int y, SDL_Surface* destination )
{
    pictureLocation.x = x;
	pictureLocation.y = y;

    SDL_BlitSurface(picture, NULL, destination, &pictureLocation);
}

void mygrafx::flip()
{
    SDL_Flip(screen);
}

void mygrafx::clean_up()
{
    SDL_FreeSurface(picture);

}
